package com.styles.codingstylemybatis.mapper.entitymapper;

import com.styles.codingstylemybatis.mapper.BaseMapper;
import com.styles.codingstylemybatis.pojo.UserEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper extends BaseMapper<UserEntity> {

    @Insert(value = "INSERT INTO users(id,user_name, password) VALUES (#{id},#{userName}, #{password})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", keyColumn = "id", resultType = Long.class, before = false)
        //@Options(useGeneratedKeys = true,keyProperty = "ID",keyColumn = "id")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userName",column = "user_name"),
            @Result(property = "password",column = "password"),
    })
    UserEntity saves(UserEntity userEntity);


    @Select(value = "SELECT * FROM users WHERE id = #{id}")
    @Results({
            @Result(property = "userName", column = "user_name"),
            @Result(property = "id", column = "id"),
            @Result(property = "password", column = "password"),
    })
    UserEntity findById(@Param("id") Long id);


}
